package com.huage_05.lesson_04;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    private DateUtils(){}
    /*
        返回值类型: String
        参数: Date date,String pattern
     */
    public static String dateToString(Date date,String pattern){
        SimpleDateFormat spf = new SimpleDateFormat(pattern);
        String time = spf.format(date);
        return time;
    }
    /*
        返回值类型: Date
        参数: String dateStr,String pattern
     */
    public static Date stringToDate(String dateStr,String pattern) throws ParseException {
        SimpleDateFormat spf = new SimpleDateFormat(pattern);
        Date date = spf.parse(dateStr);
        return date;
    }
}
